var remain_time = 60;
$(document).ready(function(){

    $("#submit").click(function(){
        var params = getInputParam("form");
        for (var k in params) {
            if (!params[k]) {
                return notify("请正确填写兑换信息");
            }
        }
        transfer(params);
       
    });


    $("#vcode").click(function() {
        var param = getInputParam('form');
        if (remain_time !== 60) {
            return notify(remain_time + '秒后重新获取');
        }

        // console.log(param);
        getSmsCode(param);
         //remain_time -= 1;

    });

    $('.maxTree').click(function(){
            $.ajax({
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/index.php/Home/Info/maxTree/" ,//url
                data:'wwww',
                success: function (result) {
                    if (result.code==1) {
                        notify(result.msg);
                    }else{
                        $("input[name='number']").val(result.msg);
                    }
                },
                error : function() {
                    notify("异常！");
                }
            });
    });
});

// 登陆的ajax
function transfer(data) {
    loading(1)
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Info/exchange/" ,//url
        data: data,
        success: function (result) {
            if (result.code == 0) {
                loading(0)
                notify(result.msg);
                window.location.href='/index.php/Home/Info/myziliao/';
            }else{
                loading(0)
                notify(result.msg);
            }
        },
        error : function() {
            loading(0)
            notify("异常！");
        }
    });
}


function getSmsCode(ob) {
    $.ajax({
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/index.php/Home/Ajax/safemsg" ,//url
        data: 'wwww',
        success: function (result) {
            notify("发送成功");
            changeRemainTime();
        },
        error : function() {
            notify("异常！");
            changeRemainTime();
        }
    })
}

function changeRemainTime() {
    sms_timer = setInterval(function() {
        remain_time--;
        if (!remain_time) {
            clearInterval(sms_timer);
             remain_time=60;
        }
        if(remain_time==60){
            $("#vcode").html('重新获取');
        }else{
           $("#vcode").html(remain_time + '秒'); 
        }
        
     }, 1000)
}